package com.sinog.front.controller.biz;

import com.sinog.core.model.UserDTO;
import com.sinog.core.util.JsonUtil;
import com.sinog.core.utilbean.Constants;
import com.sinog.core.utilbean.Result;
import com.sinog.front.config.idempotent.Idempotent;
import com.sinog.front.config.log.Log;
import com.sinog.front.feign.biz.SlgInfoService;
import com.sinog.front.service.user.UserFacade;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @desc 安置帮教管理 - 双列管 - SlgInfoController
 * @author dh
 * @date 2020-02-16-21:34
 */
@RestController
public class SlgInfoController {

    @Resource
    private UserFacade userService;
    @Resource
    private SlgInfoService slgInfoService;

    /**
     * 安置帮教管理 - 双列管 - 户籍地 - 列表
     * @param pageIndex 起始索引
     * @param pageSize 条数
     * @param pName 姓名
     * @param key 审批状态 1.审批通过 2.等待审批 3.审批失败 4.未申请
     * @param sqbegin 开始申请时间
     * @param sqend 结束申请时间
     * @param nativepro 省
     * @param nativecity 市
     * @param nativecou 区县
     * @param nativevill 村
     * @param isDoubleManage 是否双列管 1是2否
     * @param sortField 排序字段
     * @param sortOrder 排序方式
     * @return String
     */
    @RequestMapping("/azbj/bjdxInfo/slg/list")
    public String getSlgInfo(Integer pageIndex,Integer pageSize,
                             @RequestParam(required = false, defaultValue = "-1") String pName,
                             @RequestParam(required = false, defaultValue = "-1") String key,
                             @RequestParam(required = false, defaultValue = "-1") String sqbegin,
                             @RequestParam(required = false, defaultValue = "-1") String sqend,
                             @RequestParam(required = false, defaultValue = "-1") String nativepro,
                             @RequestParam(required = false, defaultValue = "-1") String nativecity,
                             @RequestParam(required = false, defaultValue = "-1") String nativecou,
                             @RequestParam(required = false, defaultValue = "-1") String nativevill,
                             @RequestParam(required = false, defaultValue = "-1") String isDoubleManage,
                             @RequestParam(required = false) String sortField,
                             @RequestParam(required = false) String sortOrder) {
        UserDTO user = userService.getAuthentication();
        Map<String,String> map = new HashMap<>(16);
        map.put("pName",pName);
        map.put("key",key);
        map.put("sqbegin",sqbegin);
        map.put("sqend",sqend);
        map.put("nativepro",nativepro);
        map.put("nativecity",nativecity);
        map.put("nativecou",nativecou);
        map.put("nativevill",nativevill);
        map.put("isDoubleManage",isDoubleManage);
        map.put("departid",user.getDepartid());
        map.put("level",user.getLevel());
        map.put("sortField",sortField);
        map.put("sortOrder",sortOrder);
        String querydata = JsonUtil.toText(map);
        return slgInfoService.getSlgHjd(pageIndex,pageSize,querydata);
    }

    /**
     * 安置帮教管理 - 双列管 - 户籍地 - 司法所双列管申请
     * @param request request
     * @param data 业务数据
     * @return Result
     */
    @Log(value = "户籍地司法所双列管申请", type = "更新")
    @Idempotent(paramPos = {1})
    @RequestMapping("/azbj/azbjgl/slg/hjdapply/save")
    public Result applySlg(HttpServletRequest request,
                           @RequestParam(required = false, defaultValue = "-1") String data) {
        UserDTO user = userService.getAuthentication();
        return slgInfoService.applySlg(data,user);
    }

    /**
     * 根据犯罪编号查询ablieguan实体
     * @param priNum 服刑人员编号
     * @return String
     */
    @RequestMapping("/azbjgl/slgapply/getinfo")
    public String getApplyInfo(@RequestParam(required = false, defaultValue = "-1") String priNum) {
        return slgInfoService.getApplyInfo(priNum);
    }

    /**
     * 安置帮教管理 - 双列管 - 居住地 - 列表
     * @param pageIndex 起始页
     * @param pageSize 止页
     * @param pName 姓名模糊搜索
     * @param key 审核状态
     * @param sqbegin 申请时间起
     * @param sqend 申请时间止
     * @param nativepro 户籍地 - 省
     * @param nativecity 户籍地 - 市
     * @param nativecou 户籍地 - 区
     * @param nativevill 户籍地 - 街道
     * @param isDoubleManage 审核状态
     * @param zdbjKey 重点帮教对象 1.是 2.否
     * @param shenKey 身份证
     * @param zmKey 罪名
     * @param nameKey 姓名
     * @param fxKey 服刑单位
     * @param qitaKey 其他条件
     * @param rjStartDate 刑期起日
     * @param rjEndDate 释放日期
     * @param sortField 排序字段
     * @param sortOrder 排序方式
     * @return String
     */
    @RequestMapping("/azbj/slg/jzdlist")
    public String getSlgJzd(Integer pageIndex,Integer pageSize,
                            @RequestParam(required = false, defaultValue = "-1") String pName,
                            @RequestParam(required = false, defaultValue = "-1") String key,
                            @RequestParam(required = false, defaultValue = "-1") String sqbegin,
                            @RequestParam(required = false, defaultValue = "-1") String sqend,
                            @RequestParam(required = false, defaultValue = "-1") String nativepro,
                            @RequestParam(required = false, defaultValue = "-1") String nativecity,
                            @RequestParam(required = false, defaultValue = "-1") String nativecou,
                            @RequestParam(required = false, defaultValue = "-1") String nativevill,
                            @RequestParam(required = false, defaultValue = "-1") String isDoubleManage,
                            @RequestParam(required = false, defaultValue = "-1") String nameKey,
                            @RequestParam(required = false, defaultValue = "-1") String zdbjKey,
                            @RequestParam(required = false, defaultValue = "-1") String shenKey,
                            @RequestParam(required = false, defaultValue = "-1") String zmKey,
                            @RequestParam(required = false, defaultValue = "-1") String fxKey,
                            @RequestParam(required = false, defaultValue = "-1") String qitaKey,
                            @RequestParam(required = false, defaultValue = "-1") String rjStartDate,
                            @RequestParam(required = false, defaultValue = "-1") String rjEndDate,
                            @RequestParam(required = false) String sortField,
                            @RequestParam(required = false) String sortOrder) {
        UserDTO user = userService.getAuthentication();
        Map<String,String> map = new HashMap<>(16);
        map.put("account",user.getAccount());
        map.put("key",StringUtils.isEmpty(key)?Constants.NumberStr.NUM_STR_FU_ONE:key);
        map.put("sqbegin",StringUtils.isEmpty(sqbegin)? Constants.NumberStr.NUM_STR_FU_ONE :sqbegin);
        map.put("pName",StringUtils.isEmpty(pName)?Constants.NumberStr.NUM_STR_FU_ONE:pName);
        map.put("sqend",StringUtils.isEmpty(sqend)?Constants.NumberStr.NUM_STR_FU_ONE:sqend);
        map.put("nativepro",StringUtils.isEmpty(nativepro)?Constants.NumberStr.NUM_STR_FU_ONE:nativepro);
        map.put("nativecity",StringUtils.isEmpty(nativecity)?Constants.NumberStr.NUM_STR_FU_ONE:nativecity);
        map.put("nativecou",StringUtils.isEmpty(nativecou)?Constants.NumberStr.NUM_STR_FU_ONE:nativecou);
        map.put("nativevill",StringUtils.isEmpty(nativevill)?Constants.NumberStr.NUM_STR_FU_ONE:nativevill);
        map.put("isDoubleManage",StringUtils.isEmpty(isDoubleManage)?Constants.NumberStr.NUM_STR_FU_ONE:isDoubleManage);
        map.put("nameKey",StringUtils.isEmpty(nameKey)?Constants.NumberStr.NUM_STR_FU_ONE:nameKey);
        map.put("zdbjKey",StringUtils.isEmpty(zdbjKey)?Constants.NumberStr.NUM_STR_FU_ONE:zdbjKey);
        map.put("shenKey",StringUtils.isEmpty(shenKey)?Constants.NumberStr.NUM_STR_FU_ONE:shenKey);
        map.put("zmKey",StringUtils.isEmpty(zmKey)?Constants.NumberStr.NUM_STR_FU_ONE:zmKey);
        map.put("fxKey",StringUtils.isEmpty(fxKey)?Constants.NumberStr.NUM_STR_FU_ONE:fxKey);
        map.put("qitaKey",StringUtils.isEmpty(qitaKey)?Constants.NumberStr.NUM_STR_FU_ONE:qitaKey);
        map.put("rjStartDate",StringUtils.isEmpty(rjStartDate)?Constants.NumberStr.NUM_STR_FU_ONE:rjStartDate);
        map.put("rjEndDate",StringUtils.isEmpty(rjEndDate)?Constants.NumberStr.NUM_STR_FU_ONE:rjEndDate);
        map.put("sortField",sortField);
        map.put("sortOrder",sortOrder);
        String querydata = JsonUtil.toText(map);
        return slgInfoService.getSlgJzd(pageIndex,pageSize,querydata,user);
    }

    /**
     * 根据犯罪编号查询ab_lieguan实体部分信息
     * @param priNum 服刑人员编号
     * @return String
     */
    @PostMapping("/azbjgl/slgapproval/getinfo")
    public String getApproveInfo(@RequestParam(required = false, defaultValue = "-1") String priNum) {
        return slgInfoService.getApproveInfo(priNum);
    }

    /**
     * 安置帮教管理 - 双列管 - 居住地 - 司法所审批通过
     * @param request request
     * @param data 业务数据
     * @return Result
     */
    @Log(type = "更新", value = "双列管居住地司法所审批")
    @Idempotent(paramPos = {1})
    @PostMapping("/azbj/azbjgl/slg/jzdapprove/save")
    public Result saveJzdApprove(HttpServletRequest request,
                                 @RequestParam(required = false, defaultValue = "-1") String data) {
        UserDTO user = userService.getAuthentication();
        return slgInfoService.saveJzdAppro(data,user);
    }

    /**
     * 根据犯罪编号和ID查询ablieguan实体部分信息
     * @param priNum 服刑人员编号
     * @param id 双列管编号
     * @return String
     */
    @PostMapping("/azbjgl/slgdetails/getinfo")
    public String getDetailsInfo(
            @RequestParam(required = false, defaultValue = "-1") String priNum,
            @RequestParam(required = false, defaultValue = "-1") String id) {
        UserDTO user = userService.getAuthentication();
        return slgInfoService.getDetailsInfo(priNum,id,user);
    }

    /**
     * 根据犯罪编号查询ablieguan实体部分信息
     * @param priNum 服刑人员编号
     * @return Result
     */
    @PostMapping("/azbj/azbjgl/slginforemove")
    public Result getRemoveSlgInfo(@RequestParam(required = false, defaultValue = "-1") String priNum) {
        return slgInfoService.getRemoveSlgInfo(priNum);
    }

    /**
     * 安置帮教管理 - 双列管 - 居住地 - 解除双列管
     * @param request request
     * @param data 业务数据
     * @return Result
     */
    @Log(type = "更新", value = "解除双列管")
    @Idempotent(paramPos = {1})
    @PostMapping("/azbj/azbjgl/slg/removeslg/save")
    public Result removeSlg(HttpServletRequest request,
                            @RequestParam(required = false, defaultValue = "-1") String data) {
        UserDTO user = userService.getAuthentication();
        return slgInfoService.removeSlg(data,user);
    }

    /**
     * 是否存在户籍地
     * @param priNum 服刑人员编号
     * @return Result
     */
    @GetMapping("/azbj/slg/checkPlaceVillexist")
    public Result checkplaceVill(@RequestParam("priNum") String priNum) {
        return slgInfoService.checkplaceVill(priNum);
    }
}